package org.mozhu.mysql.learning.hitcounter;

import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class HitCounterClient implements HitCounterService {
    private String url;

    public HitCounterClient(String url) {
        this.url = url;
    }

    @Override
    public void increase() {
        new RestTemplate().getForEntity(url + "/increase", String.class);
    }

    @Override
    public int count() {
        ResponseEntity<Integer> responseEntity = new RestTemplate().getForEntity(url + "/count", Integer.class);
        return responseEntity.getBody();
    }

    @Override
    public void reset() {
        new RestTemplate().getForEntity(url + "/reset", String.class);
    }
}
